package com.jason.data.config;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.gridfs.GridFSBucket;
import com.mongodb.client.gridfs.GridFSBuckets;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyConfig {

    @Value("${spring.data.mongodb.database}")
    private String dbName;

    @Value("${spring.data.mongodb.gridfs.bucket:fs}")
    private String bucketName;

    @Bean
    public GridFSBucket gridFSBucket(MongoClient client) {
        MongoDatabase database = client.getDatabase(dbName);
        GridFSBucket gridFSBucket = GridFSBuckets.create(database,bucketName);
        return gridFSBucket;
    }
}
